<template>
	<view class="newPartyWp">
		<view class="bgImg">
			<u-image src="https://file.casugn.com/storecompcard/temp/组局bg@2x_1682302473174.png" width="750rpx"
				height="500rpx"></u-image>
		</view>
		<u-status-bar></u-status-bar>
		<!-- 自定义导航 -->
		<u-navbar @leftClick="goBackHome" leftIconColor="#ffffff" title="待参加组局详情" bgColor="transparent"
			:titleStyle="{color:'#ffffff'}">
			<view class="u-nav-slot" slot="left">
				<view>
					<u-icon name="arrow-left" size="40" color="#ffffff"></u-icon>
				</view>
			</view>
		</u-navbar>
		<view class="headWP">
			<view class="partyItemMain">
				<view class="infoItem">
					<u-image width="32rpx" height="32rpx"
						src="https://file.casugn.com/storecompcard//8QgtIUYatKvS354eadb67fdb51a33385a045dbd14498_1682221541636.png"><template
							v-slot:loading>
							<u-loading-icon></u-loading-icon>
						</template></u-image>
					<view class="infoName u-line-1">{{partyInfo.addressName?partyInfo.addressName:''}}</view>
				</view>
				<view class="infoItem">
					<u-image width="32rpx" height="32rpx"
						src="https://file.casugn.com/storecompcard/temp/general／schedule@2x_1682221611794.png"><template
							v-slot:loading>
							<u-loading-icon></u-loading-icon>
						</template></u-image>
					<view class="infoName u-line-1">{{partyInfo.startTime?partyInfo.startTime:''}}</view>
				</view>
				<view class="infoItem">
					<u-image width="32rpx" height="32rpx"
						src="https://file.casugn.com/storecompcard/temp/general／user@2x_1682221627572.png"><template
							v-slot:loading>
							<u-loading-icon></u-loading-icon>
						</template></u-image>
					<view style="color:#276AEE ;" class="infoName">{{partyInfo.initiator?partyInfo.initiator:""}}
					</view>
				</view>
			</view>
			<view class="paddingBar">
			</view>
			<!-- 参与人员 -->
			<view class="memberWp">
				<view class="memberItemTitleWp">
					<view class="memberItemTitle">
						参与人员
					</view>
					<view class="memberItemNumber">
						{{maxCount }}人
					</view>
				</view>
				<view class="memberItem" v-for="(item,index) in membersList" :key="index">
					<view class="left" v-if="showPersonInfo(item)">
						<u-image width="80rpx" height="80rpx" :src="item.photo?item.photo:defaultHead" alt="">
						</u-image>
						<view class="userNameWp">
							<view class="userName">
								{{item.userName?item.userName:''}}
							</view>
							<view class="phone">
								{{item.mobile?item.mobile:''}}
							</view>
						</view>
					</view>
					<view class="left" v-else>
						<u-image width=" 80rpx" height="80rpx" :src="defaultHead" alt="">
						</u-image>
						<view class="userNameWp">
							<view class="userName">
								神秘嘉宾
							</view>
							<view class="phone">

							</view>
						</view>

					</view>
					<view class="right" style="margin-right: 30rpx;">

					</view>
				</view>
			</view>
			<view class="paddingBar">
			</view>
			<!-- 备注 -->
			<view class="remarkWp">
				<view class="title">
					备注
				</view>
				<view class="content">
					{{partyInfo.remark?partyInfo.remark:''}}
				</view>
			</view>
			<view class="paddingBar">
			</view>
			<view class="submitBtnWp">
				<view class="submitBtn " @click="showRefuseParty=true">
					拒绝邀请
				</view>
				<view class="submitBtn agree" @click="confirmParty">
					{{membersStatus==1?'已同意':'接受邀请'}}
				</view>

			</view>


		</view>
		<u-popup safeAreaInsetBottom :show="showRefuseParty" mode="bottom" @close="showRefuseParty=false" round="5">
			<view class="popWp">
				<view class="poptitleWp">
					<view class="blue" @click="showRefuseParty=false">
						取消
					</view>
					<view class="">
						拒绝邀请
					</view>
					<view class="blue" @click="refuseParty">
						确认
					</view>
				</view>
				<view class="inputWp">
					<view class="inputTitle">其他原因</view>
					<u--input maxlength='20' v-model="statusValue" border="bottom"
						placeholder="请输入拒绝原因(20字内)"></u--input>
				</view>
			</view>
		</u-popup>

	</view>
</template>
<script>
	import {
		mapState,
		mapGetters
	} from 'vuex'
	import {
		defaultHead
	} from '@/config/staticConfig.js'
	export default {
		components: {},
		data() {
			return {
				id: '',
				defaultHead,
				partyInfo: {
					startTime: '',
					address: '',
					remark: '',
					title: '',
				},
				initiator: '',
				openId: '',
				maxCount: 0,
				membersList: [],
				showRefuseParty: null, //是否显示控制按钮
				statusValue: '',
				membersStatus: '' //是否同意邀请

			};
		},
		computed: {
			...mapGetters(['userInfo']),


		},
		onLoad(opt) {
			uni.showLoading({
				title: '加载中'
			})
			if (opt.id) {
				this.id = opt.id
				this.queryPartyInfo(opt.id)
				this.membersStatus = opt.membersStatus
			}

		},

		methods: {
			showPersonInfo(item) {
				if (this.partyInfo.isShow == true) {
					return true
				} else {
					if (item.openId == this.userInfo.openId || item.openId == this.partyInfo.initiatorId) {
						return true
					} else {
						return false
					}
				}


			},
			// 根据id 查询组局信息
			async queryPartyInfo(groupId) {
				const {
					code,
					result
				} = await this.$api.queryGroupDetails({
					groupId,
					openId: this.userInfo.openId
				})
				if (code == 200 && result != null) {
					console.log('根据id 查询组局信息', result);
					this.partyInfo = Object.assign({}, result)
					this.addressToShow = result.addressName
					this.maxCount = result.membersList.length
					let positionAngle = 360 / result.membersList.length
					let arr = result.membersList.map((item, index) => {
						item.friendOpenId = item.openId
						item.name = item.userName
						item.head = item.photo ? item.photo : this.defaultHead
						item.ui_position = this.getAxis(positionAngle * index)
						return item
					})

					this.membersList = JSON.parse(JSON.stringify(arr))

				} else {
					uni.showToast({
						title: res.message,
						icon: 'error'
					});
					setTimeout(() => {
						uni.navigateBack()
					}, 500)

					console.log('获取组局信息失败', result);
				}
				uni.hideLoading()
			},

			getAxis(angle) {
				return `translate(${200*Math.sin(angle*Math.PI/180)+200}rpx, ${200-200*Math.cos(angle*Math.PI/180)}rpx)`
			},
			//确认参加
			async confirmParty() {
				if (this.membersStatus == 1) {
					return uni.showToast({
						title: '已确认过同意',
						icon: 'none'
					})
				}
				let payload = {
					openId: this.userInfo.openId,
					groupId: this.partyInfo.id,
					status: 1, //待处理、同意、拒绝    0 1  2   
					statusValue: ''
				}
				let res = await this.$api.handleGroupMembers(payload)
				if (res.success) {
					uni.showToast({
						title: '提交成功',
						icon: 'none'
					});
					uni.navigateBack()
				} else {
					uni.showToast({
						title: res.message,
						icon: 'none'
					});
				}

			},
			//拒绝 参加
			async refuseParty() {
				let payload = {
					openId: this.userInfo.openId,
					groupId: this.partyInfo.id,
					status: 2, //待处理、同意、拒绝   status 是  0 1  2   
					statusValue: this.statusValue
				}
				let res = await this.$api.handleGroupMembers(payload)
				if (res.success) {
					uni.showToast({
						title: '已拒绝',
						icon: 'none'
					});
					this.showRefuseParty = false
					uni.navigateBack()
				} else {
					uni.showToast({
						title: res.message,
						icon: 'none'
					});
				}

			},
			goBackHome() {
				const pageNum = getCurrentPages()
				if (pageNum.length > 1) {
					uni.navigateBack()
				} else {
					uni.switchTab({
						url: '/pages/card/card'
					})
				}
			},


		},
		// 收藏功能
		onAddToFavorites() {
			return {
				title: '组局详情',
				path: `/pagesParty/party/joinParty/joinPartyInfo?id=${this.id}&openId=${this.userInfo.openId}&membersStatus=${this.membersStatus}`,
				success: (res) => { // 收藏成功回调
					this.$uniApi.showTips('收藏成功', 'success')
				}
			}

		}

	}
</script>

<style lang="scss" scoped>
	.newPartyWp {
		min-height: 100vh;
		position: relative;
		padding-top: 1rpx;
		padding-bottom: 50rpx;

		.paddingBar {
			width: 100%;
			height: 30rpx;
			margin: 30rpx 0;
			background-color: #F7F8FA;
		}

		.bgImg {
			width: 750rpx;
			height: 500rpx;
			position: absolute;
			top: -45rpx;
			left: 0;
			z-index: -1;
			clear: both;
		}

		.headWP {
			background-color: #fff;
			border-radius: 32rpx 32rpx 0rpx 0rpx;
			margin-top: 200rpx;
			padding-top: 60rpx;

			.partyItemMain {
				margin: 0 30rpx;

				.infoItem {
					display: flex;
					align-items: center;
					margin-top: 16rpx;
					width: 100%;
					height: 40rpx;
					font-size: 28rpx;
					font-weight: 400;
					color: #4E5969;
					line-height: 39rpx;

					.infoName {
						margin-left: 16rpx;
					}

				}
			}

			.memberWp {
				margin: 0 30rpx;

				.memberItemTitleWp {
					display: flex;
					justify-content: space-between;

					.memberItemTitle {
						flex: 1;
						height: 96rpx;
						font-size: 30rpx;
						font-weight: 600;
						color: #1D2129;
						line-height: 96rpx;
					}

					.memberItemNumber {
						text-align: center;
						width: 100rpx;
						height: 96rpx;
						font-size: 28rpx;
						color: #86909C;
						line-height: 96rpx;

					}


				}



				.memberItem {
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 30upx 0;
					background: #FFFFFF;
					border-bottom: 1rpx solid #eee;

					.left {
						display: flex;
						align-items: center;
						justify-content: space-between;
						width: 438rpx;

						.userNameWp {
							margin-left: 30rpx;
							width: 440rpx;
							height: 96rpx;

							.userName {
								height: 44rpx;
								font-size: 30rpx;
								font-weight: 600;
								color: #1D2129;
								line-height: 45rpx;

								.type1 {
									margin-left: 30rpx;
									display: inline-block;
									text-align: center;
									width: 88rpx;
									height: 36rpx;
									background: #FFECE8;
									border-radius: 4rpx 4rpx 4rpx 4rpx;
									font-size: 22rpx;
									font-weight: 400;
									color: #F53F3F;
									line-height: 36rpx;

								}

								.type2 {
									margin-left: 30rpx;
									display: inline-block;
									text-align: center;
									width: 88rpx;
									height: 36rpx;
									background: #E8FFEA;
									border-radius: 4rpx 4rpx 4rpx 4rpx;
									font-size: 24rpx;
									font-weight: 400;
									color: #00B42A;
									line-height: 36rpx;

								}

							}

							.phone {
								margin-top: 16rpx;
								height: 40rpx;
								font-size: 28rpx;
								font-weight: 400;
								color: #86909C;
								line-height: 39rpx;

							}
						}

					}

					.right {

						.text {
							text-align: center;
							width: 120rpx;
							height: 56rpx;
							background: #E9F0FD;
							border-radius: 4rpx 4rpx 4rpx 4rpx;
							font-size: 28rpx;
							color: #276AEE;
							line-height: 56rpx;
						}


					}

				}

			}

			.remarkWp {
				margin: 0 30rpx;

				.title {
					height: 96rpx;
					font-size: 32rpx;
					font-weight: 600;
					color: #1D2129;
					line-height: 96rpx;
				}

				.content {
					font-size: 28rpx;
					font-weight: 400;
					color: #4E5969;
					line-height: 39rpx;
				}
			}


			.submitBtnWp {
				display: flex;
				justify-content: space-between;
				margin: 30upx;

				.submitBtn {
					margin: 30upx;
					flex: 1;
					height: 88rpx;
					font-size: 30rpx;
					font-weight: 400;
					background-color: #e9f0fd;
					color: #276AEE;
					line-height: 88rpx;
					text-align: center;

					&:hover {
						background-color: #fff;
					}

				}

				.agree {
					background-color: #276AEE;
					color: #fff;

					&:hover {
						background-color: #2873fd;

					}
				}
			}


		}

		//弹窗
		.noticeWp {
			margin: 30rpx;
			display: flex;
			justify-content: space-evenly;
			align-items: center;

			.wxshare {
				position: relative;
			}

			.wxshareBtn {
				width: 110rpx;
				height: 110rpx;
				top: 53rpx;
				left: 70rpx;
				position: absolute;
				opacity: 0;
			}

			.noticeItem {
				display: flex;
				justify-content: center;
				align-items: center;
				height: 200rpx;
				flex: 1;

				.text {
					margin-top: 10rpx;
					text-align: center;
					font-size: 24upx;
					font-weight: 600;
					color: #333333;
				}
			}
		}
	}

	.popWp {
		margin: 0 30rpx 30rpx 30rpx;


		.poptitleWp {
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 106rpx;
			font-size: 30rpx;
			font-weight: 400;
			color: #1D2129;
			line-height: 106rpx;

			.blue {
				color: #276AEE;
				width: 60rpx;
				height: 42rpx;
				font-weight: 400;
				color: #276AEE;
				line-height: 42rpx;

			}

		}

		.inputWp {
			margin: 50rpx 0;

			.inputTitle {
				font-size: 26rpx;
				font-weight: 400;
				color: #1D2129;
				line-height: 36rpx;

			}
		}
	}
</style>